package com.bjpowernode.money.utils;

import java.util.concurrent.*;

/**
 * @author ZHAOZHENYU
 * @since 2022/10/20
 */
public class ThreadPoolManager {

    private static ThreadPoolExecutor threadPoolExecutor = null;

    private static ExecutorService executorService = null;

    public static ThreadPoolExecutor getThreadPoolExecutor() {
        if (threadPoolExecutor == null) {
            synchronized (ThreadPoolManager.class) {
                if (threadPoolExecutor == null) {
                    threadPoolExecutor = new ThreadPoolExecutor(
                            3,
                            6,
                            500,
                            TimeUnit.SECONDS,
                            new ArrayBlockingQueue<>(1000));
                }
            }
        }
        return threadPoolExecutor;
    }

    public static ExecutorService getExecutorService(){
        if (executorService ==null) {
            synchronized (ThreadPoolManager.class) {
                if (executorService ==null){
                    executorService = Executors.newFixedThreadPool(32);
                }
            }
        }
        return executorService;
    }



}
